package com.hzvtc.myproject.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzvtc.myproject.dao.BackLateMapper;
import com.hzvtc.myproject.dto.ListQuery;
import com.hzvtc.myproject.entity.BackLate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BackLateService {
    @Autowired
    private BackLateMapper backLateMapper;

    @Autowired
    private BuildingService buildingService;

    /**
     * 获取 BackLate 列表的分页信息
     *
     * @param listQuery 列表查询对象
     * @param bid       建筑物 ID
     * @return BackLate 列表的分页信息
     */
    public PageInfo<BackLate> list(ListQuery<BackLate> listQuery, Long bid) {
        List<Long> bIds = buildingService.getIdsByParentId(bid);
        BackLate backLate = listQuery.getEntity();
        PageHelper.startPage(listQuery.getPage(), listQuery.getRows());
        List<BackLate> backLateList = backLateMapper.list(backLate, bIds);
        return new PageInfo<>(backLateList);
    }

    /**
     * 新增或更新 BackLate
     *
     * @param backLate BackLate 对象
     */
    public void saveOrUpdate(BackLate backLate) {
        if (backLate.getId() == null) {
            backLateMapper.save(backLate);
        } else {
            backLateMapper.update(backLate);
        }
    }

    /**
     * 删除 BackLate
     *
     * @param id BackLate ID
     */
    public void delete(Long id) {
        backLateMapper.delete(id);
    }

    /**
     * 查询 BackLate
     *
     * @param id BackLate ID
     * @return 查询到的 BackLate 对象
     */
    public BackLate query(Long id) {
        return backLateMapper.query(id);
    }
}
